<?php
namespace Home\Controller;
use Think\Controller;




class FindpwController extends Controller{


function __construct(){
        parent::__construct();
		
			if (empty($_SESSION['findpw_id'])) {
			
			
			
		echo "<script language='javascript' type='text/javascript'>window.location.href='/dqchat/register/findpw/findpw4.html'</script>";
			
		}    }   
public function findpwpr(){

$map['nuserid'] =$_SESSION['findpw_id'];


$cpwdq= M('tbuserinformation')->field('cpwdq1,cpwdq2')->where($map)->select();
$q1 = $cpwdq[0]['cpwdq1'];
$q2 = $cpwdq[0]['cpwdq2'];	
$this->assign('q1',$q1);
$this->assign('q2',$q2);
$this->display();
}
public function oper(){
$id = $_SESSION['findpw_id'];

//获取用户ID查找用户的密保问题

$map['nuserid'] =$id ;
//获取用户输入的密保答案并且校验
$data = M('tbuserinformation')->field('cpwda1,cpwda2')->where($map)->select();
$ans1 = $cpwdq[0]['cpwda1'];
$ans2= $cpwdq[0]['cpwda2'];
$da1 = I('post.ans1','');
$da2 = I('post.ans2','');
$cpwda1 =CreatePassword($da1);//密保问题1答案
$cpwda2 =CreatePassword($da2);//密保问题2答案
if(empty($da1)){
			echo 1; //答案1为空
		}else if(empty($da1)){
			echo 2;  //答案2为空
		} elseif($cpwda1!=$data[0]['cpwda1']){
		    echo 3; //问题1答案错误
		}else if($cpwda2!=$data[0]['cpwda2']){
			echo 4;//问题2答案错误
		}else if($cpwda1==$data[0]['cpwda1'] && $cpwda2==$data[0]['cpwda2']){
		    echo 5;
		   }


}
public function findpwche(){

$this->display();
}
public function changepsw(){

$id = $_SESSION['findpsw_id'];

$psw= I('post.psw'); 
$npsw['cpassword'] = CreatePassword($psw);
$map['nuserid'] =$_SESSION['findpsw_id'];
$pattern = '/[A-Za-z].*[0-9]|[0-9].*[A-Za-z]/';
if (empty($psw)) {
			  echo 1;
		  } elseif(strlen($psw)<6){
			echo 2;
		  } elseif(!preg_match($pattern,$psw)){
			echo 3;
		  }elseif(I('post.repsw')!=$psw){
			echo 4;
		  } elseif(M('tbuserinformation')->where("$id")->save($npsw)){
		  echo 5;
		   };	
	}
	public function findpwsu(){
    $this->display();
}

}
